<?php 

 

function updateVisits()
{
	
	$sql = "UPDATE settings SET visits = visits + 1";
$result = mysql_query($sql);


}



function visit(){

	$sysDate = date("Y/m/d");
  

					  $sql = "SELECT * FROM visits";
					  $result = mysql_query($sql);
					  $match = false;	
				      while ($row = mysql_fetch_array($result)) {
								  
							if(strtotime($sysDate) == strtotime($row['date'])){
									$match = true;
									$sql = "UPDATE visits SET visit_num = visit_num + 1";
									$result = mysql_query($sql);
									break;
										
											
							} 
									
					}//end while 
					
					if(!$match){
					$sql = "INSERT INTO visits values ('".$sysDate."' , '1')";
									$result = mysql_query($sql);
					
					}
					

}

function userVisit(){

	$sysDate = date("Y/m/d");
  

					  $sql = "SELECT * FROM active_users WHERE id = " . $_SESSION['id'];
					  $result = mysql_query($sql);
					  $match = false;	
				      if ($row = mysql_fetch_array($result)) {
								  
						
									$match = true;
									$sql = "UPDATE active_users SET visit_num = visit_num + 1 WHERE id = " . $_SESSION['id'];
									$result = mysql_query($sql);
									
									
					}
					
					if(!$match){
					$sql = "INSERT INTO active_users values ('".$_SESSION['id']."', '1')";
									$result = mysql_query($sql);
					
					}
					

}
	?>

